﻿@model IList<Commission.Models.Trading>
@using MyResources = Commission.Resources.AppResource

@{
    ViewBag.Title = "Index";
}

@section Sortable {
    @Scripts.Render("~/bundles/sortable")
}

<script type="text/javascript">
    function getTradingId() {
        var Ids = "";

        $('tr').each(function (i, row) {
            var $this = $(this);
            var transId = $(this).closest('tr').children('input.tradingId').val();

            if (transId === undefined) {

            } else {
                Ids = Ids + transId + "_";
            }
        });

        return Ids;
    }

    $(document).ready(function(){
        $("#updatePurchase").click(function (event) {
            $(this).attr('href', "/Product/Trading?TradingIds=" + getTradingId());
        });
    });
</script>

<h3>@MyResources.LabelTrading</h3>

@using (Html.BeginForm("Trading", "Product", FormMethod.Get))
{
    <p>
        @MyResources.LabelPurchaser : @Html.TextBox("UserName", ViewBag.CurrentFilter as string,
          new { @class = "form-control searchtext" })

        @MyResources.LabelTradeDate:
        @Html.JQueryUI().Datepicker("searchDate", ViewBag.TransactionDate,
            new { @class = "form-control-date searchtext", @style = "width:98px" })
        
        <input type="submit" value="@MyResources.LabelSearch" style="height:28px" />

        @if (User.IsInRole("Admin"))
        {
            @Html.Raw("　")
            @Html.ActionLink(@MyResources.LinkUpdateTrading, null,
                null, new { @id = "updatePurchase" })
        }
    </p>
}

<table class="table hoverTable sortable">
    <tr>
        <th style="width:160px">
            @MyResources.LabelPurchaser
        </th>

        <th style="width:150px">
            @MyResources.LabelProduct
        </th>
        
        <th class="text-center" style="width:80px" >
            @MyResources.LabelKHPrice
        </th>

        <th class="text-center" style="width:70px">
            @MyResources.LabelPPPoint
        </th>

        <th class="text-center" style="width:80px">
            @MyResources.LabelQuantity
        </th>

        <th style="width:90px">
            @MyResources.LabelUnit
        </th>

        <th class="text-center" style="width:90px">
            @MyResources.LabelTotal
        </th>

        <th class="text-center" style="width:140px">
            @MyResources.LabelTradeDate
        </th>

        <th class="text-center" style="width:140px">
            @MyResources.LabelReceivedDate
        </th>

    </tr>

    @for (int i = 0; i < Model.Count(); i++) {
    <tr>
        <td style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Customer.DisplayName)
        </td>

        <td style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Product.DisplayProduct)
        </td>
            
        <td class="text-right" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Product.Price)
        </td>
       
        <td class="text-right" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Product.PPPoint)
        </td>

        <td class="text-right" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Quantity)
        </td>

        <td class="text-center" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].Product.Unit.UnitName)
        </td>

        <td class="text-right" style="padding-top:14px;">
            @Html.Raw(string.Format("{0:#,0.00}", Model[i].Amount))
        </td>

        <td class="text-center" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].CreatedAt)
        </td>

        <td class="text-center" style="padding-top:14px;">
            @Html.DisplayFor(modelItem => Model[i].DeliveryDate)
        </td>

        @Html.Hidden("row", i)
        @Html.HiddenFor(modelItem => Model[i].TradeStatus)
        @Html.HiddenFor(modelItem => Model[i].TradingId, new { @class = "tradingId" })
    </tr>
    }
</table>